import 'package:intl/intl.dart';

class Formate {
  static String amount(num v) {
    var s = NumberFormat.compactSimpleCurrency(
        locale: 'ja', name: '￥', decimalDigits: 2);
    return s.format(v);
  }

  static String amountWithoutSymbol(num v) {
    var s = NumberFormat.decimalPattern('ja');
    return '￥' + s.format(v);
  }

  static String amountext(num v) {
    var s = NumberFormat.compactSimpleCurrency(
        locale: 'ja', name: '', decimalDigits: 2);
    return s.format(v);
  }

  static String dateTime(int v) {
    var s = DateFormat.yMd('ja')
        .add_jm()
        .format(DateTime.fromMillisecondsSinceEpoch(v));
    return s;
  }

  static String dateTest(int v) {
    var now = DateTime.now().millisecondsSinceEpoch;
    var oneDayMS = 24 * 60 * 60 * 1000;
    var inDay = (now - v) < oneDayMS;
    var inTwoDay = ((now - v) < oneDayMS * 2) && ((now - v) > oneDayMS * 1);
    var inYear = ((now - v) < oneDayMS * 365) && ((now - v) > oneDayMS * 2);
    if (inDay) {
      return '今日 ${DateFormat.jm('ja').format(DateTime.fromMillisecondsSinceEpoch(v))}';
    }
    if (inTwoDay) {
      return '昨日 ${DateFormat.jm('ja').format(DateTime.fromMillisecondsSinceEpoch(v))}';
    }
    if (inYear) {
      return DateFormat.Md('ja')
          .add_Hm()
          .format(DateTime.fromMillisecondsSinceEpoch(v));
    }
    return DateFormat.yMd('ja')
        .add_Hm()
        .format(DateTime.fromMillisecondsSinceEpoch(v));
  }

  static String date(int v) {
    var s = DateFormat.yMd('ja').format(DateTime.fromMillisecondsSinceEpoch(v));
    return s;
  }

  static String month_day(int v) {
    var s = DateFormat.Md('ja')
        .add_E()
        .format(DateTime.fromMillisecondsSinceEpoch(v));
    return s;
  }

  static num date2second(String v) {
    return DateTime.parse(v).millisecondsSinceEpoch;
  }
}
